﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

namespace HW3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            prop = new Prop();
            InitializeComponent();
        }

        private void btnInputFile_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.Title = @"Open Text File";
                openFileDialog.Filter = @"TEXT Files|*.txt";
                DialogResult result = openFileDialog.ShowDialog();
                if (result == DialogResult.OK)
                {
                    FileIsOk(openFileDialog);
                }
            }
        }

        
        private void FileIsOk(OpenFileDialog openFileDialog)
        {
            ReadFile readFile = new ReadFile(openFileDialog.FileName);
            toolStripStatusLabelFilePath.Text = openFileDialog.FileName;
            prop = readFile.setProp();
            calculateTables = new CalculateTables(prop);
            cal = new CalcTable(prop);
            for (var i = 10; i < prop.InitialAmount/2; i++)
            {
                prop.OrderMaxCondition = i;
                bool flag = cal.SimaluationTable(i);
                if (!flag)
                    i = prop.InitialAmount ;
                this.Refresh();
            }
            
            dataGridTable1.DataSource = prop.DataTable1;
            dataGridTable2.DataSource = prop.DataTable2;
            dataGridSimulationTable.DataSource = prop.SimaluationTable;
            label1.Text = @"Month outcome avarage : " + prop.DailyOutcomeAvg;
            label2.Text = @"order max condition : " + prop.OrderMaxCondition;
            label3.Text = @"Average amount of orders : " + prop.AverageAmountOfOrders;
            label4.Text = @"Average amount of losses : " + prop.AverageAmountOfLosses;

            LoadGraph();
        }

        private void LoadGraph()
        {
            // Data arrays.
            string[] seriesArray = { "Outcome" };
            int[] pointsArray = { 100, 3000 };

            // Set palette.
            this.chart1.Palette = ChartColorPalette.SeaGreen;

            // Set title.
            this.chart1.Titles.Add("Daily Outcome chart");

            // Add series.
            Series series = this.chart1.Series.Add(seriesArray[0]);
            for (var i = 0; i < prop.DailyOutcome.Count(); i++)
            {
                // Add point.
                series.Points.Add(prop.DailyOutcome[i]);
            }
        }

        private void inputFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.Title = @"Open Text File";
                openFileDialog.Filter = @"TEXT Files|*.txt";
                DialogResult result = openFileDialog.ShowDialog();
                if (result == DialogResult.OK)
                {
                    FileIsOk(openFileDialog);
                }
            }
        }




    }
}
